package pkg;

import java.io.IOException;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class TestHandler implements IRequestHandler 
{

	@Override
	public void handleRequest(HttpServletRequest request,HttpServletResponse response, IStatelessBean stateless,IStatefulBean stateful) throws ServletException, IOException 
	{

		String idString = request.getParameter("id");
    	System.out.println("Test page request id = " + idString);
    	if(idString == null) 
    	{
    		stateful.setCurrentPage(stateless.getRootPage());
    	}
    	else 
    	{
    		long id = Long.parseLong(idString);
    		stateful.setCurrentPage(stateless.getPageById(id));
    	}
    	
        RequestDispatcher rd = request.getRequestDispatcher("test3.jsp");
        rd.forward(request, response);
	}
}
